import Vue from 'vue'
import Vuex from 'vuex'
import formatTime from 'utils/formatTime'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    userInfo: {},
  },
  mutations: {
    setUserInfo(state, payload) {
      state.userInfo = payload;
      // 把信息存入localStorage中
      localStorage.setItem('ms_username', payload.username);
      localStorage.setItem('token', payload.token);
      let date = new Date();
      let time = formatTime(date, 'YYYY年MM月DD日HH时mm分');
      let pre = localStorage.getItem('preTime');
      if (!pre) {
        localStorage.setItem('preTime', time);
      }
      localStorage.setItem('time', time); // 登录时记录一个时间
    }
  },
  actions: {
  },
  modules: {
  }
})
